package com.company;

        import org.junit.Assert;

        import java.util.Random;
        import java.util.Scanner;

public class NGuessNumber {

    public static int[] generateAnswer(){
        Random random = new Random();
        int[] num = new int[4];
        int i = 0;
        while (i < 4){
            int a = random.nextInt(10);
            if (num[i] != a){
                num[i] = a;
                i++;
            }else {
                break;
            }
        }
        return num;
    }

    public static int[] getPlayerInput(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入答案");
        int[] anw = new int[4];
        for (int i = 0; i < 4; i++){
            anw[i] = scanner.nextInt();
        }
        return anw;
    }

    public static void getPlayerInputTest(){
        Assert.assertEquals(NGuessNumber.getPlayerInput().length,4);
    }


    public static void compareGuessAnswer(){
        int[] anw = NGuessNumber.getPlayerInput();
        int[] sun = NGuessNumber.generateAnswer();
        for (int i = 0; i < sun.length;i++){
            if (sun[i] != anw[i]){
                System.out.println("第"+ i + "位数字错误！");
            }else {
                System.out.println("第"+ i + "位数字正确！");
            }
        }
    }

    public static void generateAnswerTest(){
        Assert.assertEquals(NGuessNumber.generateAnswer().length,4);
    }

    public static void main(String[] args) {
        // write your code here
        NGuessNumber.generateAnswerTest();
        NGuessNumber.compareGuessAnswer();
    }
}